GrapeCity CalendarGrid for Windows Forms 3.0J > CalendarGridの使い方 > InputManCell > GcDateTime型セル > サンプルコード (CalendarGcDateTimeCellType) |
CalendarGcDateTimeCellTypeでは、和暦による日付の入力と表示が可能です。次のコードでは入力に西暦、表示には和暦を使用します。
Imports GrapeCity.Win.CalendarGrid Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan Dim today As DateTime = DateTime.Today Dim GcDateTimeCellType As New InputManCell.CalendarGcDateTimeCellType() ' 既存のフィールドをクリアする GcDateTimeCellType.Fields.Clear() GcDateTimeCellType.DisplayFields.Clear() ' キーワードから書式を設定する GcDateTimeCellType.Fields.AddRange("yyyy年MM月dd日") GcDateTimeCellType.DisplayFields.AddRange("ggg ee年MM月dd日") GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = GcDateTimeCellType ' 既定値として今日の日付を入力する GcCalendarGrid1.Content(today).Rows(1).Cells(0).Value = today GcCalendarGrid1.ScrollIntoView(today)
using GrapeCity.Win.CalendarGrid; using InputManCell = GrapeCity.Win.CalendarGrid.InputMan; var today = DateTime.Today; var gcDateTimeCellType = new InputManCell.CalendarGcDateTimeCellType(); // 既存のフィールドをクリアする gcDateTimeCellType.Fields.Clear(); gcDateTimeCellType.DisplayFields.Clear(); // キーワードから書式を設定する gcDateTimeCellType.Fields.AddRange("yyyy年MM月dd日"); gcDateTimeCellType.DisplayFields.AddRange("ggg ee年MM月dd日"); gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcDateTimeCellType; // 既定値として今日の日付を入力する gcCalendarGrid1.Content[today].Rows[1].Cells[0].Value = today; gcCalendarGrid1.ScrollIntoView(today);
既定ではドロップダウンボタンのクリックまたはF4キー、Alt+Downキーの押下によってドロップダウンカレンダーが表示されます。この動作を無効にするには、CalendarGcDateTimeCellType.DropDown.AllowDropプロパティをFalseに設定します。
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan Dim today As DateTime = DateTime.Today Dim gcDateTimeCellType As New InputManCell.CalendarGcDateTimeCellType() GcDateTimeCellType.SideButtons.Clear() GcDateTimeCellType.DropDown.AllowDrop = False GcCalendarGrid1.Content(Today).Rows(1).Cells(0).CellType = gcDateTimeCellType GcCalendarGrid1.Content(Today).Rows(1).Cells(0).CellStyle.BackColor = Color.Azure GcCalendarGrid1.ScrollIntoView(Today)
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan; var today = DateTime.Today; var gcDateTimeCellType = new InputManCell.CalendarGcDateTimeCellType(); gcDateTimeCellType.SideButtons.Clear(); gcDateTimeCellType.DropDown.AllowDrop = false; gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcDateTimeCellType; gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellStyle.BackColor = Color.Azure; gcCalendarGrid1.ScrollIntoView(today);
GcDateTime型セルの値がnullのときに、空欄の代わりに「未入力」や「null」といった文字を表示するには、CalendarGcDateTimeCellType.AlternateTextプロパティを使用します。次のコードではセルの非編集時にのみ代替文字列を表示します。
Imports GrapeCity.Win.CalendarGrid Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan Dim today As DateTime = DateTime.Today Dim gcDateTimeCellType As New InputManCell.CalendarGcDateTimeCellType() Dim alternateText As New InputManCell.AlternateText() gcDateTimeCellType.AlternateText.DisplayNull.ForeColor = Color.Red gcDateTimeCellType.AlternateText.DisplayNull.Text = "(未入力)" gcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = gcDateTimeCellType gcCalendarGrid1.ScrollIntoView(today)
using GrapeCity.Win.CalendarGrid; using InputManCell = GrapeCity.Win.CalendarGrid.InputMan; var today = DateTime.Today; var gcDateTimeCellType = new InputManCell.CalendarGcDateTimeCellType(); var alternateText = new InputManCell.AlternateText(); gcDateTimeCellType.AlternateText.DisplayNull.ForeColor = Color.Red; gcDateTimeCellType.AlternateText.DisplayNull.Text = "(未入力)"; gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcDateTimeCellType; gcCalendarGrid1.ScrollIntoView(today);
既定ではGcDateTime型セルに入力可能な日付の範囲は"0001/01/01"〜"9999/12/31"です。これをGcCalendarGridと同じ範囲に変更するには、次のようにコーディングします。
Imports GrapeCity.Win.CalendarGrid Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan Dim today As DateTime = DateTime.Today Dim gcDateTimeCellType As New InputManCell.CalendarGcDateTimeCellType() Dim alternateText As New InputManCell.AlternateText() Console.WriteLine(gcDateTimeCellType.MaxDate) Console.WriteLine(gcDateTimeCellType.MinDate) GcDateTimeCellType.MaxDate = gcCalendarGrid1.MaxDate GcDateTimeCellType.MinDate = gcCalendarGrid1.MinDate GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = gcDateTimeCellType GcCalendarGrid1.ScrollIntoView(today)
using GrapeCity.Win.CalendarGrid; using InputManCell = GrapeCity.Win.CalendarGrid.InputMan; var today = DateTime.Today; var gcDateTimeCellType = new InputManCell.CalendarGcDateTimeCellType(); var alternateText = new InputManCell.AlternateText(); Console.WriteLine(gcDateTimeCellType.MaxDate); Console.WriteLine(gcDateTimeCellType.MinDate); gcDateTimeCellType.MaxDate = gcCalendarGrid1.MaxDate; gcDateTimeCellType.MinDate = gcCalendarGrid1.MinDate; gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcDateTimeCellType; gcCalendarGrid1.ScrollIntoView(today);